package qreasymarket.movil;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginClienteActivity extends Activity {

	EditText usuario_txt;
	EditText clave_txt;
	TextView login_error;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		usuario_txt = (EditText) findViewById(R.id.usuario_txt);
		clave_txt = (EditText) findViewById(R.id.clave_txt);
		login_error = (TextView) findViewById(R.id.login_error);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	public void verificar(View view) {
		Log.i("LoguearCliente", "Enviando datos al servidor....");

		String EmailUsuario = usuario_txt.getText().toString();
		String ClaveUsuario = clave_txt.getText().toString();

		RestClient cliente = new RestClient(
				"http://192.168.1.35:8080/QR-EasyMarket_Web/rest/cliente_logueo");

		cliente.AddParam("email", EmailUsuario);
		cliente.AddParam("clave", ClaveUsuario);

		try {
			cliente.Execute(RequestMethod.GET);
			String jsontext = cliente.getResponse();
			Log.i("LoginClienteActivity", jsontext);

			jsontext = jsontext.toLowerCase().trim();

			if ("listo".equals(jsontext)) {

				Intent i = new Intent(LoginClienteActivity.this,AlertaDeliveryActivity.class);
				Bundle datos = new Bundle();
				datos.putString("valor1", EmailUsuario);
				i.putExtras(datos);

				startActivity(i);

				//Toast tt = Toast.makeText(getBaseContext(), "Bienvenido" + " "+ EmailUsuario, 2000);
				//tt.show();

			} else if ("error".equals(jsontext)) {
				Toast tt = Toast.makeText(getBaseContext(), "Hubo un error",
						2000);
				tt.show();
			}
		} catch (Exception e) {
			Log.i("LoginClienteActivity", ":" + e.getMessage());
		}
	}
}
